package com.wisdom.core.enums;

import com.wisdom.core.exception.RpcException;

/**
 * @description: <支出的负载均衡算法>
 * @author: Leo
 * @date: 2021-08-29 16:18
 */
public enum LoadBalanceStrategy {

    RANDOM("random"),
    POLLING("polling"),
    HASH("hash"),
    WEIGHT_RANDOM("weightRandom");

    private String value;

    private LoadBalanceStrategy(String value){
        this.value = value;
    }

    public static LoadBalanceStrategy getLoadBalanceStrategy(String value) {
        LoadBalanceStrategy balanceStrategy = null;
        LoadBalanceStrategy[] values = LoadBalanceStrategy.values();
        for (LoadBalanceStrategy strategy : values) {
            if (strategy.value.equals(value)){
                balanceStrategy =  strategy;
            }
        }
        if (balanceStrategy == null){
            throw new RpcException(StatusEnum.LOAD_BALANCE_ERROR);
        }
        return balanceStrategy;
    }

    public String getValue() {
        return value;
    }
}
